package edu.drexel.jrexel2d.networking.socket;

import java.io.IOException;
import java.net.DatagramSocket;
import java.net.InetAddress;

import edu.drexel.jrexel2d.networking.GamePacket;

public abstract class GameSocket {
	protected byte[] receiveData = new byte[1024];
	protected byte[] sendData = new byte[1024];

	protected DatagramSocket socket;
	protected InetAddress ip;
	protected int port;

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public DatagramSocket getSocket() {
		return socket;
	}

	public void setSocket(DatagramSocket socket) {
		this.socket = socket;
	}

	public InetAddress getIp() {
		return ip;
	}

	public void setIp(InetAddress ip) {
		this.ip = ip;
	}

	public void send(GamePacket gamePacket) {
		try {
			socket.send(gamePacket.getPacket());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	/*
	 * public boolean hasData(){ Game return(socket.receive(null)!=null);
	 * 
	 * 
	 * }
	 */

	public boolean receive(GamePacket receivePacket) {
		try {
			socket.receive(receivePacket.getPacket());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			// e.printStackTrace();
			// System.out.println("Nothing recieved.");
			return false;
		}
		return true;

	}

}
